﻿using System;
using System.ServiceProcess;

using SBPweb.RouTorrent.Business;
using SBPweb.RouTorrent.Service.Properties;

namespace SBPweb.RouTorrent.Service
{
    public partial class MainService : ServiceBase
    {

        #region Private fields

        private Settings mSettings;

        #endregion

        #region Protected fields

        protected DownloadManager mDownloadManager;
        protected string[] mArgs;

        #endregion

        #region Constructor logic

        public MainService()
            : this(null)
        {
        }

        public MainService(string[] args)
        {
            mSettings = global::SBPweb.RouTorrent.Service.Properties.Settings.Default;
            mArgs = args;

            InitializeComponent();
        }

        #endregion

        #region Service event handlers

        protected override void OnStart(string[] args)
        {
            InitializeDownloadManager();
        }

        protected override void OnStop()
        {
            FinalizeDownloadManager();
        }

        #endregion

        #region Public properties

        public DownloadManager DownloadManager
        {
            get
            {
                return mDownloadManager;
            }
        }

        #endregion

        #region Public methods

        public void InitializeDownloadManager()
        {
            mDownloadManager = new DownloadManager();

            //mDownloadManager.PathOfDownloadedFiles = global::SBPweb.RouTorrent.Service.Properties.Settings.Default.PathOfDownloaded;
            //mDownloadManager.PathOfTemporaryFiles = global::SBPweb.RouTorrent.Service.Properties.Settings.Default.PathOfTemporary;

            mDownloadManager.Initialize();
        }

        public void FinalizeDownloadManager()
        {
            mDownloadManager.Finalize();
        }

        public void Start()
        {
            OnStart(mArgs);
        }

        #endregion

    }
}